Hints are used as a general mechanism to supply directives to the query optimizer when it compiles a SQL statement that influences the plan generated by the compilation process. For example, hints can direct the optimizer to use a particular access path for a table, a specific join method for a join, or a particular join order for the tables. Hints can also be used to provide accurate object or system statistics, to correct optimizer cardinality or cost estimates, or to specify certain optimizer modes (e.g., set an optimizer mode to ALL_ROWS, which causes the plan, when executed, to fetch all the resulting rows of the query). In fact, the entire execution plan can be specified via hints (e.g. in the form of an outline). Hence, hints are one of the main mechanisms used by a database administrator (DBA) to tune, either manually or automatically, the execution plans produced by the optimizer.
Hints can be broadly classified as single-table hints, multi-table hints, query block hints, or statement hints. Single-table hints, such as INDEX and USE_NL (use a nested loop) for example, provide information for processing one table or view, and multi-table hints contain information that can be applied to several tables. A query block hint, such as STAR_TRANSFORMATION and UNNEST for example, operates on a single query block. A statement hint, such as ALL_ROWS, for example, is applied to the entire SQL statement.
Existing hints have several drawbacks. For example, manual hints created by the DBA have to be specified in the query blocks which are being tuned. This requires actually embedding the hint in the query blocks of the SQL statement. However, most packaged applications do not allow the DBA to access the code for the SQL statement, so the DBA is unable to physically insert the hint into the SQL statement. Furthermore, manually inserting a hint into a SQL statement might improve query performance for a while, but can hinder the performance when the system or object characteristics (e.g., workload, object statistics) change, the database is revised, or the software application program is upgraded.
Another disadvantage to the conventional approach for hints is due to query block transformations. Manual hints can be provided for query blocks that are present in the original SQL statement. However, query blocks are often transformed during the compilation process. The DBA cannot know what a transformed query block will look like. Moreover, even if the DBA knew what the query block would be, since it is dynamically generated during the compilation process, there is no way to physically add the hint inside the transformed query block.